package run.halo.app.content;

import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import run.halo.app.core.extension.content.Post;

@Data
@Accessors(chain = true)
public class IMXWGGListPostResponseItemDto {
    private String image;
    private String subTitle;
    private String createTime;
    private String appName;
    private String title;
    private String jumpUrl;

    /**
     * Creates from snapshot.
     */
    public static IMXWGGListPostResponseItemDto from(Post post,String homePagePrefix) {
        IMXWGGListPostResponseItemDto itemDto = new IMXWGGListPostResponseItemDto()
                .setTitle(post.getSpec().getTitle())
                .setCreateTime(post.getSpec().getPublishTime() == null ? "" : post.getSpec().getPublishTime().toString())
                .setSubTitle("点击查看详情")
                .setAppName("分类名字")
                .setJumpUrl(post.getStatus().getPermalink());
        if (!StringUtils.isBlank(post.getSpec().getCover())) {
            itemDto.setImage(post.getSpec().getCover());
        }
        itemDto.setJumpUrl(homePagePrefix+post.getStatus().getPermalink());
        return itemDto;
    }
}
